
  <script LANGUAGE="javascript">
function check()
{
  <%#*if(document.getElementById('checkall').innerHtml=="Select All")%>
      if(document.getElementById('checkstatus').value==1)
    {
      document.getElementById('selectall').innerHTML="Deselect All";
          var inputs = document.getElementsByTagName('input');
          var checkboxes = [];
          for (var i = 0; i < inputs.length; i++) {

              if (inputs[i].type == 'checkbox') {
              inputs[i].checked =true;

              }

          }
           document.getElementById('checkstatus').value=0;


    }
    else if(document.getElementById('checkstatus').value==0)
    {

      document.getElementById('selectall').innerHTML="Select All";
          var inputs = document.getElementsByTagName('input');
          var checkboxes = [];
          for (var i = 0; i < inputs.length; i++) {

              if (inputs[i].type == 'checkbox') {
              inputs[i].checked =false;

              }
          }


document.getElementById('checkstatus').value=1;    }

}
</script>
  <%require 'htmlentities'
  coder = HTMLEntities.new
  %>
<div class="user-accounts-left-column">
    	<div class="user-accounts-image-container">
        	<div class="user-accounts-image">
	          <%=image_tag("user-accounts-image.jpg", :border=>"0px",:width=>"148") -%>
    		</div>
            <div class="user-accounts-edit-image">
            	<a href="">Add an image</a>
            </div>
        </div>
        <div class="user-accounts-fields">
        	<div class="user-accounts-username">
            	<%= User.find(session[:user]).full_name -%>
            </div>
            <div class="user-accounts-type">
              <%unless User.find(session[:user]).user_type_id.nil?%>
            	<%= UserType.find(User.find(session[:user]).user_type_id).name -%>
                <%end -%>
            </div>
            <div class="user-accounts-university">
            	Delhi University
            </div>
        </div>
        <div class="user-accounts-buttons">
        	<div class="user-accounts-post-button">
            	<%=image_tag("user-accounts-post-button.jpg", :border=>"0px",:width=>"150") -%>
            </div>
        	<div class="user-accounts-invite-button">
                <%=image_tag("user-accounts-invite-button.jpg", :border=>"0px",:width=>"150") -%>
            </div>
        	<div class="user-accounts-find-button">
                <%=image_tag("user-accounts-find-button.jpg", :border=>"0px",:width=>"150") -%>
            </div>
        	<div class="user-accounts-settings-button">
               <%=image_tag("user-accounts-settings-button.jpg", :border=>"0px",:width=>"150") -%>
            </div>
        </div>
        <div class="user-accounts-bar">
        	<div class="user-accounts-bar-image">
             <%=image_tag("user-accounts-bar.jpg", :border=>"0px",:width=>"150") -%>
            </div>
            <div class="user-accounts-bar-reading">
            	Your profile is 25%.<br/>
                Complete it. <a>Edit</a>
            </div>
        </div>
    </div>
    <div class="user-accounts-right-column">
    	<div class="user-accounts-welcome">
        	Welcome <%= User.find(session[:user].id).full_name -%>,
        </div>
        <div class="user-accounts-tab">
            <ul>
                <li class="selected"><a href="">Dashboard</a></li>
                <li><%= link_to  "My Ads" ,:controller=>"login",:action => "recently_posted_ads" -%></li>
                <li><%=link_to_remote "My Info", :url=>{:action => "my_info", :id =>session[:user].id,:controller=>"login"},:update=>"user-accounts-dashboard" %></li>
                <li><%= link_to_remote  "Saved Ads" ,:url => {:controller=>"login",:action => "saved_ads"}, :update => "user-accounts-dashboard" -%></li>
                <li><a href="">Notification</a></li>
            </ul>
        </div>
        <div class="user-accounts-profile-view">
          <%=image_tag("others-profile-view.jpg", :border=>"0px",:width=>"20",:height=>"20") -%>
             <a href="">View my profile as others see it</a>
        </div>
        <div class="user-accounts-dashboard" id="user-accounts-dashboard">
          <div class="user-accounts-my-ads" style="border:0px">
    <% form_for :advertisments, :url => {:controller=>"login", :action => "delete_renew_multiple_advertisments" , :id => params[:id] } do |adform| %>

                    <div class="my-ads-select-all">
            	<div class="select-all-options">
                  <input type="hidden" id="checkstatus" value="1">
                	<div id="selectall" class="select-all-link" style="color:#0000ff;cursor:pointer" onclick="check();">
                      Select All
                    </div>
                    <div class="my-ads-delete">
                    	<%= image_submit_tag "select-all-delete.jpg", :width=>"54", :height=>"21", :border=>"0",:value=>"delete",:name=>"submit" ,:confirm=>"Are you sure?"%>
                    </div>
                    <div class="my-ads-delete">
                      <%= image_submit_tag "select-all-renew.jpg", :width=>"54", :height=>"21", :border=>"0",:value=>"renew",:name=>"submit"  -%>
                    </div>
                   
                </div>
                <div class="my-ads-pages">


                    	<%= will_paginate(@user_advertisments)%>

                </div>
            </div>

            <div class="table-header">
            	<div class="table-header-ad">
                	Ad
                </div>
                <div class="table-header-responses">
                	 <%=link_to_remote "Responses" + image_tag("sort-arrow.png", :width=>"6", :height=>"6", :border=>"0"), :url=>{:controller=>"login", :action=>"sort_by_responses"}, :update=>"user-accounts-dashboard",:method=>"GET" -%>
                </div>
                <div class="table-header-relevant">
                	Relevant Ads <%= image_tag "sort-arrow.png", :width=>"6", :height=>"6", :border=>"0"  %>
                </div>
                <div class="table-header-action">
                	Actions
                </div>
            </div>


        <%@user_advertisments.each do |advertisment| -%>
          <div class="my-ads-listing" id="my-ads-listings-<%=advertisment.id%>">
            	<div class="my-ads-details">
                	<div class="my-ads-checkbox">
                      <input type="checkbox" name="dfo[]" id="my_ad_<%= advertisment.id %>" value="<%= advertisment.id -%>" /><br>
                    </div>
                    <div id="my-ads-details-fields" class="my-ads-details-fields">
                    	<div class="my-ads-ad-title">
                          	<%#=link_to_remote "Edit", :url=>{:action => "edit_ad",:controller=>"login", :id => advertisment.id},:update=>"user-accounts-dashboard",:method=>"GET" -%>
                        	<%=link_to_remote advertisment.title, :url=>{:controller=>"login", :action=>"show_advertisment", :id=>advertisment.id} ,:update=>"user-accounts-dashboard",:method=>"GET" -%>
                        </div>
                        <div class="my-ads-posted-in">
                        	<div class="my-ads-posted-text">
                            	Posted in:
                        	</div>
                            <div class="my-ads-posted-value">
                            	<%= University.find(advertisment.university_id).name %>
                            </div>
                        </div>
                        <div class="my-ads-posted-in">
                        	<div class="my-ads-posted-text">
                            	Posted on:
                        	</div>
                            <div class="my-ads-posted-value">
                            	<%= advertisment.created_at.to_formatted_s(:long_ordinal) %>
                            </div>
                        </div>

                              <%
                                  @sub_category_id        = advertisment.sub_category_id
                                  @sub_category_lifespan  = SubCategory.find(@sub_category_id).lifespan
                                  @category               = SubCategory.find(@sub_category_id).category_id
                              %>

                       <%if @category!=2%>
                        <div class="my-ads-posted-in">
                        	<div class="my-ads-posted-text">
                            	Expires on:
                        	</div>
                            <div class="my-ads-posted-value">
                             
                              <%  @expires= advertisment.created_at + @sub_category_lifespan.days -%>
                              <%= @expires.to_formatted_s(:long_ordinal) %>
                            </div>
                        </div>
                       <%end-%>
                    </div>
                    <div class="my-ads-responses">
                    	<a href=""><%= @count=Query.count(:conditions=>"advertisment_id="+advertisment.id.to_s,:order=>"created_at desc")-%></a>
                    </div>
                    <div class="my-ads-responses">
                    	<a href="">         <%count=0%>
                            <%@subcategory_id=advertisment.sub_category_id -%>
                            <%@category_id=SubCategory.find(@subcategory_id).category_id-%>
                            <%@group_id=Category.find(@category_id).group_id-%>
                            <%@opposite_category_ids=Category.find(:all,:conditions=>"id!="+@category_id.to_s+ " and group_id="+@group_id.to_s)-%>
                                <%@opposite_category_ids.each do |category| -%>
                                <%@opposite_subcategory_ids=SubCategory.find(:all,:conditions=>"category_id="+category.id.to_s)-%>
                                <%@opposite_subcategory_ids.each do |subcategory| -%>


                                <%count=count+Advertisment.count(:conditions=>"sub_category_id = "+subcategory.id.to_s,:order =>"created_at DESC")%>

                                <%end -%>
                            <%end -%>

 <%=count%>
</a>
                    </div>
                    <div class="my-ads-actions">
                    	<div class="ad-edit">
                        	<div class="ad-edit-button">
                              <%=link_to_remote image_tag("edit-ad.png",:border=>0), :url=>{:action => "edit_ad",:controller=>"login", :id => advertisment.id}, :update=>"my-ads-listings-"+advertisment.id.to_s,:method=>"GET" -%>
                            </div>
                            <div class="ad-edit-link">
                            	<%=link_to_remote "Edit", :url=>{:action => "edit_ad",:controller=>"login", :id => advertisment.id},:update=>"user-accounts-dashboard",:method=>"GET" -%>
                            </div>
                        </div>
                                            	<div class="ad-edit">
                        	<div class="ad-edit-button">
                              <%=link_to image_tag("delete-ad.png",:border=>0), :advertisment=>advertisment.id, :action=>"delete_advertisment"%>
                            </div>
                            <div class="ad-edit-link">
                              <%= link_to "Delete", {:advertisment=>advertisment.id, :action=>"delete_advertisment"}, :confirm => "Are you sure?"%>
                            </div>
                        </div>
                                            	<div class="ad-edit">
                        	<div class="ad-edit-button">
                              <%=link_to image_tag("renew-ad.png",:border=>0)%>
                            </div>
                            <div class="ad-edit-link">
                            <%= link_to_remote  "Renew",:url=>{:controller=>"login", :action=>"renew_advertisment",:id=>advertisment.id.to_s}, :update=>"user-accounts-dashboard" %>
                            </div>
                        </div>
                                            	
                    </div>
                </div>
            </div>

      <%end -%>
  <%end -%>




        </div>

        </div>
    </div>




